package com.example.yichuangyun.ui.activity.mine;

import android.os.Bundle;
import android.widget.ImageView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.bumptech.glide.Glide;
import com.example.yichuangyun.R;
import com.example.yichuangyun.utils.CommonUtil;

import fm.jiecao.jcvideoplayer_lib.JCVideoPlayer;
import fm.jiecao.jcvideoplayer_lib.JCVideoPlayerStandard;

/**
 * 常见问题
 */
public class QuestionActivity extends AppCompatActivity {

    private JCVideoPlayerStandard jcXiaomiRecordSet;
    private JCVideoPlayerStandard jcHuaweiRecordSet;
    private JCVideoPlayerStandard jcXiaomiSetPermission;
    private JCVideoPlayerStandard jcHuaweiSetPermission;
    private JCVideoPlayerStandard jcHuawei9ASetPermission;
    private JCVideoPlayerStandard jcXiaomiFileManager;
    private JCVideoPlayerStandard jcHuaweiFileManager;
    private JCVideoPlayerStandard jcXiaomiNote8SetPermission;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_question);
        CommonUtil.requestTranslucentStatusBar(this, true);
        jcXiaomiRecordSet = findViewById(R.id.jc_xiaomi_record_set);
        jcHuaweiRecordSet = findViewById(R.id.jc_huawei_record_set);
        jcXiaomiSetPermission = findViewById(R.id.jc_xiaomi_setPermission);
        jcHuaweiSetPermission = findViewById(R.id.jc_huawei_setPermission);
        jcHuawei9ASetPermission = findViewById(R.id.jc_huawei_9A_setPermission);
        jcXiaomiFileManager = findViewById(R.id.jc_xiaomi_fileManager);
        jcHuaweiFileManager = findViewById(R.id.jc_huawei_fileManager);
        jcXiaomiNote8SetPermission = findViewById(R.id.jc_xiaomi_note8_setPermission);
        ImageView ivBack = findViewById(R.id.iv_back);
        ivBack.setOnClickListener(v -> finish());
        initPlayer();
    }

    /**
     * jcPlayer需要继承AppCompatActivity，否则会报错
     * java.lang.NullPointerException: Attempt to invoke virtual method 'androidx.appcompat.app.AppCompatActivity.getSupportActionBar()' on a null object reference
     */
    private void initPlayer() {
        Glide.with(this).load(R.mipmap.xiaomi_set_record).into(jcXiaomiRecordSet.thumbImageView);
        Glide.with(this).load(R.mipmap.huawei_set_record).into(jcHuaweiRecordSet.thumbImageView);
        Glide.with(this).load(R.mipmap.xiaomi_set_permission).into(jcXiaomiSetPermission.thumbImageView);
        Glide.with(this).load(R.mipmap.huawei_set_permission).into(jcHuaweiSetPermission.thumbImageView);
        Glide.with(this).load(R.mipmap.huawei_9a_set_permission).into(jcHuawei9ASetPermission.thumbImageView);
        Glide.with(this).load(R.mipmap.xiaomi_file_manager).into(jcXiaomiFileManager.thumbImageView);
        Glide.with(this).load(R.mipmap.huawei_set_permission).into(jcHuaweiFileManager.thumbImageView);
        Glide.with(this).load(R.mipmap.xiaomi_note8_file_manager).into(jcXiaomiNote8SetPermission.thumbImageView);

        String play_base_url = "https://ycydown.yikaiye.net/";
        String xiaomi_set_record = play_base_url + "setAllowRecord.mp4";
        jcXiaomiRecordSet.setUp(xiaomi_set_record, JCVideoPlayer.SCREEN_LAYOUT_LIST, "");

        String huawei_set_record = play_base_url + "callList-menu-callRecordsetOpen.mp4";
        jcHuaweiRecordSet.setUp(huawei_set_record, JCVideoPlayer.SCREEN_LAYOUT_LIST, "");

        String xiaomi_set_permission = play_base_url + "setAllPermission.mp4";
        jcXiaomiSetPermission.setUp(xiaomi_set_permission, JCVideoPlayer.SCREEN_LAYOUT_LIST, "");

        String huawei_set_permission = play_base_url + "allPermissionOpen.mp4";
        jcHuaweiSetPermission.setUp(huawei_set_permission, JCVideoPlayer.SCREEN_LAYOUT_LIST, "");

        String huawei_a9_set_permission = play_base_url + "openPermissionVideo.mp4";
        jcHuawei9ASetPermission.setUp(huawei_a9_set_permission, JCVideoPlayer.SCREEN_LAYOUT_LIST, "");

        String xiaomi_fileManager = play_base_url + "file-Download1";
        jcXiaomiFileManager.setUp(xiaomi_fileManager, JCVideoPlayer.SCREEN_LAYOUT_LIST, "");

        String huawei_fileManager = play_base_url + "file-Download2";
        jcHuaweiFileManager.setUp(huawei_fileManager, JCVideoPlayer.SCREEN_LAYOUT_LIST, "");

        String xiaomi_note8_fileManager = play_base_url + "file-Download3";
        jcXiaomiNote8SetPermission.setUp(xiaomi_note8_fileManager, JCVideoPlayer.SCREEN_LAYOUT_LIST, "");
    }

    @Override
    public void onBackPressed() {
        // 全屏竖屏切换的时候继续播放
        if (JCVideoPlayerStandard.backPress()) {
            return;
        }
        super.onBackPressed();
    }

    @Override
    public void onPause() {
        super.onPause();
        JCVideoPlayerStandard.releaseAllVideos();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        // activity销毁的时候释放资源，播放器停止播放
        JCVideoPlayerStandard.releaseAllVideos();
    }
}